package com.caiyi.financial.nirvana.sms.filters;

import com.caiyi.financial.nirvana.sms.entity.SmsUser;
import com.caiyi.financial.nirvana.sms.param.SendMsgParam;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 过滤链
 *
 * @author lvchaohua
 */
public class FilterChain {

    /**
     * 模板是否匹配标志
     */
    private String templateCode;
    /**
     * 链表
     **/
    private List<Filter> filters = new ArrayList<>();
    /**
     * 调用链上的过滤器时，记录过滤器的位置用
     **/
    private int index = 0;
    /**
     * 用户提交数据
     **/
    private SendMsgParam param;
    /**
     * 用户信息
     */
    private SmsUser smsUser;

    /**
     * 手机号码集合
     */
    private Set<String> phones;

    /**
     * 请求ip
     */
    private String ip;

    public FilterChain(SendMsgParam param) {
        this.param = param;
    }

    public void addFilter(Filter f) {
        filters.add(f);
    }

    public void doFilter() {
        if (index == filters.size())
            return;
        Filter f = filters.get(index);
        index++;
        f.run(this);
    }

    public SendMsgParam getParam() {
        return param;
    }

    public void setParam(SendMsgParam param) {
        this.param = param;
    }

    public SmsUser getSmsUser() {
        return smsUser;
    }

    public void setSmsUser(SmsUser smsUser) {
        this.smsUser = smsUser;
    }

    public Set<String> getPhones() {
        return phones;
    }

    public void setPhones(Set<String> phones) {
        this.phones = phones;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getTemplateCode() {
        return templateCode;
    }

    public void setTemplateCode(String templateCode) {
        this.templateCode = templateCode;
    }
}
